package com.xiaou.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xiaou.pojo.Items;
import com.xiaou.service.ItemsService;


@Controller
public class ItemsController {
	@Autowired
	private ItemsService itemsService;
	
	@RequestMapping("/list.action")
	public ModelAndView list() {
		List<Items> list = itemsService.queryItemList();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("itemList", list);
		modelAndView.setViewName("/itemList");
		return modelAndView;
	}
	
	@RequestMapping("/itemEdit.action")
	public ModelAndView itemEdit(Integer id) {
		Items item = itemsService.selectItemById(id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("item", item);
		modelAndView.setViewName("/editItem");
		return modelAndView;
	}
	
	@RequestMapping("/updateitem.action")
	public ModelAndView updateItem(Items item) {
		itemsService.updateItem(item);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/success");
		return modelAndView;
	}
}
